<?php

/*
 * 测试单例模式
 */

namespace App\Controller;

use App\DesignPattern\Register\EnvRegister;
use App\DesignPattern\Factory\OrmFactory;
use App\DesignPattern\Singleton\LogSingleton;


class ControllerRegister{
	
	private function actionIndexBefore(){
		EnvRegister::add('orm', OrmFactory::createOrm());
		EnvRegister::add('log', LogSingleton::getInstance());
	}
	
	private function actionIndexAfter(){
		$log = EnvRegister::get('log');
		$log->write("这是我第二次写入");
		EnvRegister::delete('log');
		EnvRegister::clean();
	}
	
	public function actionIndex(){
		$this->actionIndexBefore();
		$log = EnvRegister::get('log');
		$log->write("这是我第一次写入");
		$this->actionIndexAfter();
	}
}
